package io.github.wslxm.springbootplus2.manage.login.controller;

import io.github.wslxm.springbootplus2.core.constant.BaseConstant;
import io.github.wslxm.springbootplus2.core.result.Result;
import io.github.wslxm.springbootplus2.manage.login.model.dto.LoginDTO;
import io.github.wslxm.springbootplus2.manage.login.service.LoginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录控制器
 *
 * @author wangsong
 * @date 2023/05/17
 */
@RestController
@RequestMapping(BaseConstant.Uri.API_ADMIN + "/sys/login")
@Tag(name = "base--sys--登录")
public class LoginController {

    @Autowired
    private LoginService loginService;


    @Operation(summary = "用户登录")
    @PostMapping
    public Result<Boolean> login(@RequestBody @Validated LoginDTO dto) {
        return Result.success(loginService.login(dto));
    }


    @Operation(summary ="登出 (当前登录账号)")
    @PostMapping("/loginOut")
    public Result<Boolean> loginOut() {
        return Result.success(loginService.loginOut());
    }


    @PostMapping(value = "/isLoginEnvironment")
    @Operation(summary = "获取登录环境是否与上次相同 (true=相同 false=不相同)", description = "如果环境不同必须先通过行为验逻辑获取行为验的验证Id,否则无法登录")
    public Result<Boolean> isLoginCaptchaVerify(@RequestBody LoginDTO dto) {
        return Result.success(loginService.isLoginEnvironment(dto));
    }

}
